package name.fowler.refactoring.simplestore.domain;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

@Entity
public class Rental extends JPAEntity{
    @OneToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
    private Movie movie;
	private int daysRented;

    protected Rental() {
    }

    Rental(Movie movie, int daysRented) {
		this.movie = movie;
		this.daysRented = daysRented;
	}

	public int getDaysRented() {
		return daysRented;
	}

	public Movie getMovie() {
		return movie;
	}

    public double getAmount() {
        return movie.getPriceCode().getAmount(daysRented);
    }

    public int getRentalFrequentPoints() {
        return movie.getPriceCode().getFrequentPoints(daysRented);
    }

}

